import React from 'react';
import dayjs from 'dayjs';
import { Button, Popover, Tag } from '@arco-design/web-react';
import { MessageType } from '@arco-design/web-react/es/Message';

function getColumns(
  callback: (record, type) => Promise<MessageType>
) {
  return [
    {
      title: 'Id',
      dataIndex: 'id',
    },
    {
      title: '邮件',
      dataIndex: 'email',
      width: 180,
    },
    {
      title: 'SMTP_Server',
      dataIndex: 'smtp_server',
      width: 180,
    },
    {
      title: 'SMTP端口',
      dataIndex: 'smtp_port',
      width: 180,
    },
    {
      title: '账号',
      dataIndex: 'username',
      width: 180,
      ellipsis: true,
    },
    {
      title: '密钥',
      dataIndex: 'password',
      width: 100,
      ellipsis: true,
    },
    {
      title: '是否默认',
      dataIndex: 'is_default',
      width: 100,
      render: (_, record)=> {
        return record.is_default ? "是" : "否"
      }
    },
    {
      title: '创建时间',
      dataIndex: 'created_at',
      width: 180,
      render: (value) => dayjs(value).format('YYYY-MM-DD HH:mm:ss')
    },
    {
      title: '更新时间',
      dataIndex: 'updated_at',
      width: 180,
      render: (value) => dayjs(value).format('YYYY-MM-DD HH:mm:ss')
    },
    {
      title: '发送日志',
      dataIndex: 'points_log',
      render: (_, record) => (
        <Button
          type="text"
          size="small"
          onClick={() => callback(record, 'view_logs')}
        >
          查看日志
        </Button>
      )
    },
    {
      title: '操作',
      dataIndex: 'operate',
      fixed: 'right',
      width: 180,
      render: (_, record) => (
        <div>
          <Tag
            size="small"
            onClick={() => callback(record, 'edit')}
          >
            编辑
          </Tag>
          <Tag
            size="small"
            onClick={() => callback(record, 'test')}
          >
            测试发送
          </Tag>
          <Tag
            size="small"
            onClick={() => callback(record, 'delete')}
            disabled={record.is_admin}
          >
            删除
          </Tag>
        </div>
      ),
    },
  ];
}
export default getColumns;